<template>
  <div>
    <!-- 面包屑部分 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 搜索区域 -->
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input placeholder="请输入搜索内容" v-model="orderQueryInfo.query"  clearable @clear="getOrderList">
          <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
           </el-input>
        </el-col>
      </el-row>
      <el-table
        :data="orderList"
        border
        style="width: 100%">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="300">
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格">
        </el-table-column>
        <el-table-column
          prop="order_pay"
          label="是否付款"
          width="120">
          <template v-slot="scope">
            <el-tag v-if="scope.row.order_pay === '1'" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货"
          width="120">
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="下单时间">
          <template v-slot="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column
          prop="order_id"
          label="操作">
          <template >
             <el-button type="primary" size="mini" class="el-icon-edit" @click="editAddress"></el-button>
              <el-button type="success" size="mini" class="el-icon-setting" @click="lookMap"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
    title="物流信息"
    width="50%"
    :visible.sync="mapDialogVisiable"
    @close="closeDia">
      <el-timeline :reverse="true">
      <el-timeline-item
        v-for="(activity, index) in mapData"
        :key="index"
        :timestamp="activity.time">
        {{activity.context}}
      </el-timeline-item>
    </el-timeline>
    </el-dialog>
    <!-- 修改地址对话框 -->
    <el-dialog
    title="修改地址"
    width="50%"
    :visible.sync="addressDialogVisiable"
    @close="addressCloseDia">
      <el-form :model="address" :rules="adrFormRules" ref="adrFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省/市/区" prop="address1">
          <el-cascader
            v-model="address.address1"
            :options="cityData"
            :props="{ expandTrigger: 'hover' }"
            ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="address.address2"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
export default {
  data () {
    return {
      orderQueryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      mapData: [],
      mapDialogVisiable: false,
      cityData,
      addressDialogVisiable: false,
      address: {
        address1: [],
        address2: ''
      },
      adrFormRules: {
        address1: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        address2: [{ required: true, message: '请输入活动名称', trigger: 'blur' }]
      }

    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.orderQueryInfo })
      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.total = res.data.total
      this.orderList = res.data.goods
    },
    async lookMap () {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) return this.$message.error('获取物流信息失败')
      this.mapData = res.data
      this.mapDialogVisiable = true
    },
    closeDia () {
      this.mapData = []
      this.mapDialogVisiable = false
    },
    addressCloseDia () {
      this.address = {
        address1: [],
        address2: ''
      }
    },
    editAddress () {
      this.addressDialogVisiable = true
    }
  }
}
</script>

<style scoped lang="less">

</style>
